package com.kws.merchant.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kws.common.config.constant.MinioCommonBucket;
import com.kws.merchant.domain.TradePowerStationEntity;
import com.kws.merchant.domain.po.TradePowerStationPo;
import com.kws.merchant.mapper.TradePowerStationMapper;
import com.kws.merchant.service.TradePowerStationService;
import com.kws.merchant.util.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author : zhangbenting
 * @date : 2024/11/21 15:42
 * @Version: 1.0
 */
@Service
public class TradePowerStationServiceImpl extends ServiceImpl<TradePowerStationMapper, TradePowerStationEntity> implements TradePowerStationService {

    @Autowired
    private FileUtil fileUtil;

    @Override
    public Page<TradePowerStationEntity> tradePowerStation(TradePowerStationPo tradePowerStationPo) {
        Page<TradePowerStationEntity> page = new Page<>();
        LambdaQueryWrapper<TradePowerStationEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.like(StringUtils.isNotEmpty(tradePowerStationPo.getStationName()),TradePowerStationEntity::getStationName, tradePowerStationPo.getStationName());
        wrapper.like(StringUtils.isNotEmpty(tradePowerStationPo.getStationAddress()),TradePowerStationEntity::getStationAddress, tradePowerStationPo.getStationAddress());
        wrapper.eq(TradePowerStationEntity::getEnable, "1");
        Page<TradePowerStationEntity> stationEntityPage = this.page(page, wrapper);
        List<TradePowerStationEntity> records = stationEntityPage.getRecords();
        for (TradePowerStationEntity tradePowerStation : records) {
            //todo 计算用户和商家之间的距离

            tradePowerStation.setStationImg(fileUtil.fixFileName() + tradePowerStation.getStationImg());
        }
        return stationEntityPage;
    }
}
